New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MYST-268 Add endpoint and CLI command for current IP #118
Conversation
tequilapi/client/client.go
Outdated
@@ -110,6 +110,20 @@ func (client *Client) Status() (status StatusDto, err error) { | |||
return status, err | |||
} | |||
|
|||
func (client *Client) Ip() (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetIP()
tequilapi/client/client.go
Outdated
defer response.Body.Close() | ||
|
||
var ipData struct { | ||
Ip string `json:"ip"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IP
tequilapi/endpoints/current_ip.go
Outdated
) | ||
|
||
type currentIPEndpoint struct { | ||
ipResolver ipResolver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All ipifyClient
could be this dependency. And finally it could be renamed ipifyClient
-> IPResolver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure I understood the suggestion - are you suggesting to refactor ipify.Client
interface with all its implementations into functions (instead of a classes), i.e.:
func ipify.NewClient (ipify.Client, error)
-> func ipify.NewIPResolver (IPResolver, error)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I suggest to inject full ipifyClient here ipResolver ipify.Client
tequilapi/http_routes.go
Outdated
func NewAPIRouter() *httprouter.Router { | ||
router := httprouter.New() | ||
router.HandleMethodNotAllowed = true | ||
|
||
router.GET("/healthcheck", endpoints.HealthCheckEndpointFactory(time.Now, os.Getpid).HealthCheck) | ||
|
||
ipifyClient := ipify.NewClient() | ||
router.GET("/ip", endpoints.NewCurrentIPEndpoint(ipifyClient.GetPublicIP).CurrentIP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can make a more generic endpoint and call it /network which can return more network information, not only ip?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not hard to rename later on if we have to add more fields - for now, all it does is return IP, because that's the user story.
tequilapi/http_routes.go
Outdated
func NewAPIRouter() *httprouter.Router { | ||
router := httprouter.New() | ||
router.HandleMethodNotAllowed = true | ||
|
||
router.GET("/healthcheck", endpoints.HealthCheckEndpointFactory(time.Now, os.Getpid).HealthCheck) | ||
|
||
ipifyClient := ipify.NewClient() | ||
router.GET("/ip", endpoints.NewCurrentIPEndpoint(ipifyClient.GetPublicIP).CurrentIP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should go somewhere under /v1..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe GET /v1/connection/ip
is right place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have /v1
, but it makes sense to move it inside connection
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved to connection
tequilapi/http_routes.go
Outdated
func NewAPIRouter() *httprouter.Router { | ||
router := httprouter.New() | ||
router.HandleMethodNotAllowed = true | ||
|
||
router.GET("/healthcheck", endpoints.HealthCheckEndpointFactory(time.Now, os.Getpid).HealthCheck) | ||
|
||
ipifyClient := ipify.NewClient() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont factory on the fly, pass dependency from upper layer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I just noticed that NewAPIRouter()
factory is not right place to connect features
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to connection endpoints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, added dependency injection.
476781d
to
82545d1
Compare
@Waldz fixed all issues, ready for review :) |
ip/rest_resolver.go
Outdated
const IPIFY_API_CLIENT = "goclient-v0.1" | ||
const IPIFY_API_LOG_PREFIX = "[ipify.api] " | ||
const IpifyAPIURL = "https://api.ipify.org/" | ||
const IpifiAPICLient = "goclient-v0.1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ipifi
-> Ipify..
- Could be private constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
type Client interface { | ||
type Resolver interface { | ||
GetPublicIP() (string, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be 2 implementations with same ip. Resolver
interface e.g. NewPublicResolver()
, NewOutboundResolver()
8fc707d
to
738377e
Compare
738377e
to
1552e06
Compare
No description provided.